package com.caijin.web.controller.system;


import com.caijin.common.constant.UserConstants;
import com.caijin.common.core.domain.Result;
import com.caijin.common.core.domain.entity.Course;
import com.caijin.system.service.ICourseService;
import com.caijin.system.service.IStudentClazzService;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 课程 基本业务处理
 *
 * @author Peas
 * @since 2021-01-18
 */
@RestController
@RequestMapping("/system/course")
@CrossOrigin
public class CourseController {

    @Autowired
    private ICourseService courseService;

    @Autowired
    private IStudentClazzService studentClazzService;

    /**
     * 创建课程
     */
    @ApiOperation(value = "创建课程")
    @RequestMapping(path = "/createCourse", method = RequestMethod.POST)
    public Result createCourse(@RequestBody Course course) {
        return courseService.createCourse(course);
    }

    /**
     * 获取课程列表
     */
    @ApiOperation(value = "获取课程列表")
    @RequestMapping(path = "/getCourseList", method = RequestMethod.GET)
    public Result getCourseList(@RequestParam("userType") String userType,
                                @RequestParam("userId") Long userId) {
        return StringUtils.equals(UserConstants.STUDENT_TYPE, userType) ? studentClazzService.getCourseListBySno(userId) : courseService.getCourseListByTno(userId);
    }

}

